package com.wu.web;

import com.alibaba.fastjson.JSON;
import com.wu.bean.User;
import com.wu.service.UserService;
import com.wu.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 根据用户名查询用户信息
 */
@WebServlet("/SelectUserName")
public class SelectUserNameServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getSession().getAttribute("username").toString();
        UserService userService=new UserServiceImpl();
        User user = userService.queryUsername(username);
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String json= JSON.toJSON(user).toString();

        resp.getWriter().print(json);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
